<template>
  <div class="photoinfo-container">
    <h3>{{photoinfo.title}}</h3>
    <p class="subtitle">
      <span>发表时间：{{ photoinfo.add_time | dateFormat }}</span>
      <span>点击：{{ photoinfo.click }}次</span>
    </p>
    <hr />
    <!-- 缩略图区域 -->
    <div class="thumbs">
      <!-- 缩略图插件更新了，下面代码不点击事件无效了 -->
      <!-- <img
        class="preview-img"
        v-for="(item, index) in list"
        :src="item.src"
        height="100"
        @click="$preview.open(index, list)"
        :key="item.src"
      />-->
      <!-- vue-preview插件更新后，实现缩略图 -->
      <vue-preview :slides="list"></vue-preview>
    </div>

    <!-- 图片内容区域 -->
    <div class="content" v-html="photoinfo.content"></div>

    <!-- 图片评论子组件 -->
    <cmt-box :id="this.id"></cmt-box>
  </div>
</template>

<script>
// 导入评论子组件
import comment from "../../components/subcomponents/comment.vue";
export default {
  data() {
    return {
      id: this.$route.params.id, //从路由中获取到的图片Id
      photoinfo: {}, //图片详情
      list: [], //缩略图数组
    };
  },
  created() {
    this.getImageInfo();
    this.getThumbs();
  },
  methods: {
    // 获取图片版详情
    getImageInfo() {
      this.$http.get("api/getimageInfo/" + this.id).then((result) => {
        if (result.body.status === 0) {
          this.photoinfo = result.body.message[0];
        } else {
          Toast("获取图片详情失败");
        }
      });
    },
    //获取缩略图
    getThumbs() {
      this.$http.get("api/getthumimages/" + this.id).then((result) => {
        if (result.body.status === 0) {
          // 补全每个图片的宽和高
          result.body.message.forEach((item) => {
            item.w = 600;
            item.h = 400;
            // 插件更新以后，多了一个msrc属性
            item.msrc = item.src;
          });
          this.list = result.body.message;
        }
      });
    },
  },
  components: {
    //注册评论子组件
    "cmt-box": comment,
  },
};
</script>

<style lang="scss" scoped>
.photoinfo-container {
  padding: 3px;
  h3 {
    color: #26a2ff;
    font-size: 15px;
    text-align: center;
    margin: 15px 0;
  }
  .subtitle {
    display: flex;
    font-size: 13px;
    justify-content: space-between;
  }
  .content {
    font-size: 13px;
    line-height: 30px;
  }
}
</style>